package cc.mrbird.febs.buss.service.impl;

import cc.mrbird.febs.common.entity.FebsConstant;
import cc.mrbird.febs.common.entity.QueryRequest;
import cc.mrbird.febs.buss.entity.MenuItemFile;
import cc.mrbird.febs.buss.mapper.MenuItemFileMapper;
import cc.mrbird.febs.buss.service.IMenuItemFileService;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.beans.factory.annotation.Autowired;
import cc.mrbird.febs.common.utils.SortUtil;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;

import java.util.*;
/**
 *  Service实现
 *
 * @author Lujingyuan
 * @date 2021-10-11 19:58:07
 */
@Service
@Transactional(propagation = Propagation.SUPPORTS, readOnly = true, rollbackFor = Exception.class)
public class MenuItemFileServiceImpl extends ServiceImpl<MenuItemFileMapper, MenuItemFile> implements IMenuItemFileService {

    @Autowired
    private MenuItemFileMapper menuItemFileMapper;


    @Override
    public IPage<MenuItemFile> findMenuItemFileDetail(QueryRequest request, HashMap<String,String> map) {
        Page<MenuItemFile> page = new Page<MenuItemFile>(request.getPageNum(), request.getPageSize());
        SortUtil.handlePageSort(request, page, "id", FebsConstant.ORDER_ASC, false);
        return this.baseMapper.findMenuItemFileDetailPageByMap(page,map);
    }

    @Override
    public List<MenuItemFile> findMenuItemFiles(MenuItemFile menuItemFile) {
	    LambdaQueryWrapper<MenuItemFile> queryWrapper = new LambdaQueryWrapper<>();
		// TODO 设置查询条件
		return this.baseMapper.selectList(queryWrapper);
    }

    @Override
    @Transactional
    public void add (MenuItemFile menuItemFile) {
        menuItemFile.setId(UUID.randomUUID().toString().replace("-", "").toLowerCase());
        menuItemFileMapper.insertOne(menuItemFile);
    }

    @Override
    @Transactional
    public void updateMenuItemFile(MenuItemFile menuItemFile) {
        this.saveOrUpdate(menuItemFile);
    }

    @Override
    @Transactional
    public void deleteMenuItemFile(MenuItemFile menuItemFile) {
        LambdaQueryWrapper<MenuItemFile> wrapper = new LambdaQueryWrapper<>();
	    // TODO 设置删除条件
	    this.remove(wrapper);
	}

    @Override
    @Transactional
    public void deleteMenuItemFile(String[] ids) {
        List<String> list = Arrays.asList(ids);
        // 删除用户
        this.removeByIds(list);
    }

    @Override
    public List<MenuItemFile> selectByMap(Map<String,Object> map){
        return menuItemFileMapper.selectByMap(map);
    }

    @Override
    public List<MenuItemFile> selectConnByMap(Map<String, Object> map) {
        return menuItemFileMapper.selectConnByMap(map);
    }
}
